/**
 * 
 */
package com.googlecode.iant;

import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Jar;
import org.apache.tools.ant.taskdefs.Javac;
import org.springframework.core.io.Resource;

/**
 * @author ccPascu
 *
 */
public class AntFacade {

	public static Project createAntProject(Resource resource) {
		final Project project = new Project();
		try {
			project.setBaseDir(resource.getFile().getParentFile());
			final DefaultLogger logger = new DefaultLogger();
			logger.setMessageOutputLevel(Project.MSG_INFO);
	        logger.setOutputPrintStream(System.out);
	        logger.setErrorPrintStream(System.err);
			project.addBuildListener(logger);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		return project;
	}

	public static Jar newJarTask(Project antProject) {
		final Jar jar = new Jar();
		jar.setTaskName("jar");
		jar.setProject(antProject);
		return jar;
	}

	public static Javac newJavacTask(Project antProject) {
		final Javac javac = new Javac();
		javac.setTaskName("javac");
		javac.setProject(antProject);
		return javac;
	}

}
